/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.Vector;

import javax.bluetooth.DiscoveryAgent;
import javax.bluetooth.LocalDevice;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.ImageItem;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.StringItem;
import javax.microedition.lcdui.TextBox;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;


/**
 * @author Pedro
 */
public class HelloMIDlet extends MIDlet implements CommandListener {

    private boolean midletPaused = false;
    private LocalDevice local = null;
    private DiscoveryAgent agent = null;
    private Vector devicesFound = null;
    private Thread tServer = null, tClient = null;
    public int networkId = 0;
    private static RmiClient client = null;
    // <editor-fold defaultstate="collapsed"
    //<editor-fold defaultstate="collapsed" desc=" Generated Fields ">//GEN-BEGIN:|fields|0|
    private Command exitCommand;
    private Command okCommand;
    private Command okCommand1;
    private Command backCommand;
    private Command okCommand2;
    private Command exitCommand1;
    private Command okCommand3;
    private Form form;
    private TextField txtLogin;
    private TextField txtSenha;
    private TextBox textBox;
    private List list;
    private Alert alert;
    private Form form2;
    private ImageItem imageItem1;
    private StringItem stringItem1;
    private Form form1;
    private StringItem stringItem;
    private ImageItem imageItem;
    private TextBox textBox1;
    private Image image2;
    private Image image;
    //</editor-fold>//GEN-END:|fields|0|

    /**
     * The HelloMIDlet constructor.
     */
    public HelloMIDlet() {
    }

    // <editor-fold defaultstate="collapsed"
    //<editor-fold defaultstate="collapsed" desc=" Generated Methods ">//GEN-BEGIN:|methods|0|
    //</editor-fold>//GEN-END:|methods|0|
    //<editor-fold defaultstate="collapsed" desc=" Generated Method: initialize ">//GEN-BEGIN:|0-initialize|0|0-preInitialize
    /**
     * Initilizes the application.
     * It is called only once when the MIDlet is started. The method is called before the <code>startMIDlet</code> method.
     */
    private void initialize() {//GEN-END:|0-initialize|0|0-preInitialize
            client = RmiClient.getInstance();
            imageItem = new ImageItem("", getImage2(), ImageItem.LAYOUT_CENTER | Item.LAYOUT_TOP | Item.LAYOUT_BOTTOM | Item.LAYOUT_VCENTER | Item.LAYOUT_2, "<Imagem perdida>", Item.PLAIN);//GEN-LINE:|0-initialize|1|0-postInitialize
            // write post-initialize user code here
    }//GEN-BEGIN:|0-initialize|2|
    //</editor-fold>//GEN-END:|0-initialize|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: startMIDlet ">//GEN-BEGIN:|3-startMIDlet|0|3-preAction
    /**
     * Performs an action assigned to the Mobile Device - MIDlet Started point.
     */
    public void startMIDlet() {//GEN-END:|3-startMIDlet|0|3-preAction

        switchDisplayable(null, getForm());//GEN-LINE:|3-startMIDlet|1|3-postAction
            // write post-action user code here
    }//GEN-BEGIN:|3-startMIDlet|2|
    //</editor-fold>//GEN-END:|3-startMIDlet|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: resumeMIDlet ">//GEN-BEGIN:|4-resumeMIDlet|0|4-preAction
    /**
     * Performs an action assigned to the Mobile Device - MIDlet Resumed point.
     */
    public void resumeMIDlet() {//GEN-END:|4-resumeMIDlet|0|4-preAction
            // write pre-action user code here
//GEN-LINE:|4-resumeMIDlet|1|4-postAction
            // write post-action user code here
    }//GEN-BEGIN:|4-resumeMIDlet|2|
    //</editor-fold>//GEN-END:|4-resumeMIDlet|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: switchDisplayable ">//GEN-BEGIN:|5-switchDisplayable|0|5-preSwitch
    /**
     * Switches a current displayable in a display. The <code>display</code> instance is taken from <code>getDisplay</code> method. This method is used by all actions in the design for switching displayable.
     * @param alert the Alert which is temporarily set to the display; if <code>null</code>, then <code>nextDisplayable</code> is set immediately
     * @param nextDisplayable the Displayable to be set
     */
    public void switchDisplayable(Alert alert, Displayable nextDisplayable) {//GEN-END:|5-switchDisplayable|0|5-preSwitch
            // write pre-switch user code here
        Display display = getDisplay();//GEN-BEGIN:|5-switchDisplayable|1|5-postSwitch
        if (alert == null) {
            display.setCurrent(nextDisplayable);
        } else {
            display.setCurrent(alert, nextDisplayable);
        }//GEN-END:|5-switchDisplayable|1|5-postSwitch
            // write post-switch user code here
    }//GEN-BEGIN:|5-switchDisplayable|2|
    //</editor-fold>//GEN-END:|5-switchDisplayable|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: isValidAuth ">//GEN-BEGIN:|43-if|0|43-preIf
    /**
     * Performs an action assigned to the isValidAuth if-point.
     */
    public void isValidAuth() {//GEN-END:|43-if|0|43-preIf
            try {
                // enter pre-if user code here
                if (true || client.isValidAuthentication(txtLogin.getString(), txtSenha.getString())) {//GEN-LINE:|43-if|1|44-preAction
                // write pre-action user code here
                    switchDisplayable(null, getTextBox());//GEN-LINE:|43-if|2|44-postAction
                // write post-action user code here
                } else {//GEN-LINE:|43-if|3|45-preAction
                // write pre-action user code here
                    switchDisplayable(null, getAlert());//GEN-LINE:|43-if|4|45-postAction
                // write post-action user code here
                }//GEN-LINE:|43-if|5|43-postIf
            } catch (Exception e) {
                System.out.println(e.getMessage());
            }
    }//GEN-BEGIN:|43-if|6|
    //</editor-fold>//GEN-END:|43-if|6|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: commandAction for Displayables ">//GEN-BEGIN:|7-commandAction|0|7-preCommandAction
    /**
     * Called by a system to indicated that a command has been invoked on a particular displayable.
     * @param command the Command that was invoked
     * @param displayable the Displayable where the command was invoked
     */
    public void commandAction(Command command, Displayable displayable) {//GEN-END:|7-commandAction|0|7-preCommandAction
            // write pre-action user code here
        if (displayable == form) {//GEN-BEGIN:|7-commandAction|1|19-preAction
            if (command == exitCommand) {//GEN-END:|7-commandAction|1|19-preAction
                    // write pre-action user code here
                exitMIDlet();//GEN-LINE:|7-commandAction|2|19-postAction
                    // write post-action user code here
            } else if (command == okCommand) {//GEN-LINE:|7-commandAction|3|26-preAction
                    // write pre-action user code here
                isValidAuth();//GEN-LINE:|7-commandAction|4|26-postAction
                    // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|5|53-preAction
        } else if (displayable == list) {
            if (command == List.SELECT_COMMAND) {//GEN-END:|7-commandAction|5|53-preAction
                    // write pre-action user code here
                listAction();//GEN-LINE:|7-commandAction|6|53-postAction
                    // write post-action user code here
            } else if (command == exitCommand1) {//GEN-LINE:|7-commandAction|7|61-preAction
                           if(client != null)
        {
            try {
                client.removeUserFromNetwork(txtLogin.getString(), networkId);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
                switchDisplayable(null, getTextBox1());//GEN-LINE:|7-commandAction|8|61-postAction
                    // write post-action user code here
            } else if (command == okCommand2) {//GEN-LINE:|7-commandAction|9|59-preAction
                    // write pre-action user code here
                switchDisplayable(null, getForm1());//GEN-LINE:|7-commandAction|10|59-postAction
                    try {
                        String[] songs = client.requestSongs(txtLogin.getString(), networkId);
                        preencheLista(songs);
                        switchDisplayable(null, getList());
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
            }//GEN-BEGIN:|7-commandAction|11|37-preAction
        } else if (displayable == textBox) {
            if (command == backCommand) {//GEN-END:|7-commandAction|11|37-preAction
                    // write pre-action user code here
//GEN-LINE:|7-commandAction|12|37-postAction
                    // write post-action user code here
            } else if (command == okCommand1) {//GEN-LINE:|7-commandAction|13|35-preAction

                    switchDisplayable(null, getForm2());
                try {
                    Thread.sleep(10);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }

                    ClientBt cliente = new ClientBt(client, txtLogin.getString());
                    Thread tClientFindService = new Thread(cliente);
                    tClientFindService.start();

                    while (!cliente.completedServicesSearch);
                    System.out.println("Serviços achados : " + cliente.servicosAchados);

                    if (cliente.servicosAchados <= 0)// <editor-fold defaultstate="collapsed" desc="comment">
                    {// </editor-fold>
                        try {

                            networkId = client.getNewNetworkId();
                            System.out.println(networkId);
                            client.requestSongs(txtLogin.getString(), networkId);
                        } catch (Exception ex) {
                            System.out.println(ex.getMessage());
                        }
                    } else {
                        networkId = cliente.networkId;
                    }

                    Thread tServer = new Thread(new ServerBt(txtLogin.getString(), networkId));
                    tServer.start();


                    switchDisplayable(null, getForm1());//GEN-LINE:|7-commandAction|14|35-postAction
                    try {
                        String[] songs = client.requestSongs(txtLogin.getString(), networkId);
                        preencheLista(songs);
                        switchDisplayable(null, getList());
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }


            }//GEN-BEGIN:|7-commandAction|15|77-preAction
        } else if (displayable == textBox1) {
            if (command == okCommand3) {//GEN-END:|7-commandAction|15|77-preAction
                // write pre-action user code here
                exitMIDlet();//GEN-LINE:|7-commandAction|16|77-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|17|7-postCommandAction
        }//GEN-END:|7-commandAction|17|7-postCommandAction
            // write post-action user code here
    }//GEN-BEGIN:|7-commandAction|18|
    //</editor-fold>//GEN-END:|7-commandAction|18|

    public void preencheLista(String[] songs) {
        List lista = this.getList();
        lista.deleteAll();
        for (int i = 0; i < songs.length; i++) {
            lista.append(songs[i], null);
        }

    }

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: exitCommand ">//GEN-BEGIN:|18-getter|0|18-preInit
    /**
     * Returns an initiliazed instance of exitCommand component.
     * @return the initialized component instance
     */
    public Command getExitCommand() {
        if (exitCommand == null) {//GEN-END:|18-getter|0|18-preInit
                // write pre-init user code here
            exitCommand = new Command("Exit", Command.EXIT, 0);//GEN-LINE:|18-getter|1|18-postInit
                // write post-init user code here
        }//GEN-BEGIN:|18-getter|2|
        return exitCommand;
    }
    //</editor-fold>//GEN-END:|18-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: okCommand ">//GEN-BEGIN:|25-getter|0|25-preInit
    /**
     * Returns an initiliazed instance of okCommand component.
     * @return the initialized component instance
     */
    public Command getOkCommand() {
        if (okCommand == null) {//GEN-END:|25-getter|0|25-preInit
                // write pre-init user code here
            okCommand = new Command("Ok", Command.OK, 0);//GEN-LINE:|25-getter|1|25-postInit
                // write post-init user code here
        }//GEN-BEGIN:|25-getter|2|
        return okCommand;
    }
    //</editor-fold>//GEN-END:|25-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: okCommand1 ">//GEN-BEGIN:|34-getter|0|34-preInit
    /**
     * Returns an initiliazed instance of okCommand1 component.
     * @return the initialized component instance
     */
    public Command getOkCommand1() {
        if (okCommand1 == null) {//GEN-END:|34-getter|0|34-preInit
                // write pre-init user code here
            okCommand1 = new Command("Ok", Command.OK, 0);//GEN-LINE:|34-getter|1|34-postInit
                // write post-init user code here
        }//GEN-BEGIN:|34-getter|2|
        return okCommand1;
    }
    //</editor-fold>//GEN-END:|34-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand ">//GEN-BEGIN:|36-getter|0|36-preInit
    /**
     * Returns an initiliazed instance of backCommand component.
     * @return the initialized component instance
     */
    public Command getBackCommand() {
        if (backCommand == null) {//GEN-END:|36-getter|0|36-preInit
                // write pre-init user code here
            backCommand = new Command("Voltar", Command.BACK, 0);//GEN-LINE:|36-getter|1|36-postInit
                // write post-init user code here
        }//GEN-BEGIN:|36-getter|2|
        return backCommand;
    }
    //</editor-fold>//GEN-END:|36-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: form ">//GEN-BEGIN:|14-getter|0|14-preInit
    /**
     * Returns an initiliazed instance of form component.
     * @return the initialized component instance
     */
    public Form getForm() {
        if (form == null) {//GEN-END:|14-getter|0|14-preInit
                // write pre-init user code here
            form = new Form("Login :", new Item[] { getTxtLogin(), getTxtSenha() });//GEN-BEGIN:|14-getter|1|14-postInit
            form.addCommand(getExitCommand());
            form.addCommand(getOkCommand());
            form.setCommandListener(this);//GEN-END:|14-getter|1|14-postInit
                // write post-init user code here
        }//GEN-BEGIN:|14-getter|2|
        return form;
    }
    //</editor-fold>//GEN-END:|14-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: txtLogin ">//GEN-BEGIN:|23-getter|0|23-preInit
    /**
     * Returns an initiliazed instance of txtLogin component.
     * @return the initialized component instance
     */
    public TextField getTxtLogin() {
        if (txtLogin == null) {//GEN-END:|23-getter|0|23-preInit
                // write pre-init user code here
            txtLogin = new TextField("Nome de Usu\u00E1rio :", "", 32, TextField.ANY);//GEN-BEGIN:|23-getter|1|23-postInit
            txtLogin.setLayout(ImageItem.LAYOUT_LEFT | Item.LAYOUT_2);//GEN-END:|23-getter|1|23-postInit
                // write post-init user code here
        }//GEN-BEGIN:|23-getter|2|
        return txtLogin;
    }
    //</editor-fold>//GEN-END:|23-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: txtSenha ">//GEN-BEGIN:|24-getter|0|24-preInit
    /**
     * Returns an initiliazed instance of txtSenha component.
     * @return the initialized component instance
     */
    public TextField getTxtSenha() {
        if (txtSenha == null) {//GEN-END:|24-getter|0|24-preInit
                // write pre-init user code here
            txtSenha = new TextField("Senha :", "", 32, TextField.ANY | TextField.PASSWORD);//GEN-BEGIN:|24-getter|1|24-postInit
            txtSenha.setInitialInputMode("UCB_BASIC_LATIN");//GEN-END:|24-getter|1|24-postInit
                // write post-init user code here
        }//GEN-BEGIN:|24-getter|2|
        return txtSenha;
    }
    //</editor-fold>//GEN-END:|24-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: textBox ">//GEN-BEGIN:|32-getter|0|32-preInit
    /**
     * Returns an initiliazed instance of textBox component.
     * @return the initialized component instance
     */
    public TextBox getTextBox() {
        if (textBox == null) {//GEN-END:|32-getter|0|32-preInit
                // write pre-init user code here
            textBox = new TextBox("Caro usu\u00E1rio :", "Ola " + txtLogin.getString() + " Este aplicativo precisará acessar alguns dados da sua conta Last.fm. Deseja continuar?", 500, TextField.ANY);//GEN-BEGIN:|32-getter|1|32-postInit
            textBox.addCommand(getOkCommand1());
            textBox.addCommand(getBackCommand());
            textBox.setCommandListener(this);//GEN-END:|32-getter|1|32-postInit
                // write post-init user code here
        }//GEN-BEGIN:|32-getter|2|
        return textBox;
    }
    //</editor-fold>//GEN-END:|32-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: alert ">//GEN-BEGIN:|48-getter|0|48-preInit
    /**
     * Returns an initiliazed instance of alert component.
     * @return the initialized component instance
     */
    public Alert getAlert() {
        if (alert == null) {//GEN-END:|48-getter|0|48-preInit
                // write pre-init user code here
            alert = new Alert("Erro!", "Os dados enviados n\u00E3o conferem com o login e senha v\u00E1lidos do Last.fm", null, AlertType.ERROR);//GEN-BEGIN:|48-getter|1|48-postInit
            alert.setTimeout(Alert.FOREVER);//GEN-END:|48-getter|1|48-postInit
                // write post-init user code here
        }//GEN-BEGIN:|48-getter|2|
        return alert;
    }
    //</editor-fold>//GEN-END:|48-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: list ">//GEN-BEGIN:|51-getter|0|51-preInit
    /**
     * Returns an initiliazed instance of list component.
     * @return the initialized component instance
     */
    public List getList() {
        if (list == null) {//GEN-END:|51-getter|0|51-preInit
                // write pre-init user code here
            list = new List("M\u00FAsicas Recomendadas para o Ambiente", Choice.IMPLICIT);//GEN-BEGIN:|51-getter|1|51-postInit
            list.append("Elemento da lista 1", null);
            list.append("Elemento da lista 2", null);
            list.append("Elemento da lista 3", null);
            list.addCommand(getOkCommand2());
            list.addCommand(getExitCommand1());
            list.setCommandListener(this);
            list.setFitPolicy(Choice.TEXT_WRAP_DEFAULT);
            list.setSelectedFlags(new boolean[] { false, false, false });//GEN-END:|51-getter|1|51-postInit
                // write post-init user code here
        }//GEN-BEGIN:|51-getter|2|
        return list;
    }
    //</editor-fold>//GEN-END:|51-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: listAction ">//GEN-BEGIN:|51-action|0|51-preAction
    /**
     * Performs an action assigned to the selected list element in the list component.
     */
    public void listAction() {//GEN-END:|51-action|0|51-preAction
            // enter pre-action user code here
        String __selectedString = getList().getString(getList().getSelectedIndex());//GEN-BEGIN:|51-action|1|55-preAction
        if (__selectedString != null) {
            if (__selectedString.equals("Elemento da lista 1")) {//GEN-END:|51-action|1|55-preAction
                    // write pre-action user code here
//GEN-LINE:|51-action|2|55-postAction
                    // write post-action user code here
            } else if (__selectedString.equals("Elemento da lista 2")) {//GEN-LINE:|51-action|3|56-preAction
                    // write pre-action user code here
//GEN-LINE:|51-action|4|56-postAction
                    // write post-action user code here
            } else if (__selectedString.equals("Elemento da lista 3")) {//GEN-LINE:|51-action|5|57-preAction
                    // write pre-action user code here
//GEN-LINE:|51-action|6|57-postAction
                    // write post-action user code here
            }//GEN-BEGIN:|51-action|7|51-postAction
        }//GEN-END:|51-action|7|51-postAction
            // enter post-action user code here
    }//GEN-BEGIN:|51-action|8|
    //</editor-fold>//GEN-END:|51-action|8|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: okCommand2 ">//GEN-BEGIN:|58-getter|0|58-preInit
    /**
     * Returns an initiliazed instance of okCommand2 component.
     * @return the initialized component instance
     */
    public Command getOkCommand2() {
        if (okCommand2 == null) {//GEN-END:|58-getter|0|58-preInit
                // write pre-init user code here
            okCommand2 = new Command("Ok", Command.OK, 0);//GEN-LINE:|58-getter|1|58-postInit
                // write post-init user code here
        }//GEN-BEGIN:|58-getter|2|
        return okCommand2;
    }
    //</editor-fold>//GEN-END:|58-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: exitCommand1 ">//GEN-BEGIN:|60-getter|0|60-preInit
    /**
     * Returns an initiliazed instance of exitCommand1 component.
     * @return the initialized component instance
     */
    public Command getExitCommand1() {
        if (exitCommand1 == null) {//GEN-END:|60-getter|0|60-preInit
                // write pre-init user code here
            exitCommand1 = new Command("Sair", Command.EXIT, 0);//GEN-LINE:|60-getter|1|60-postInit
                // write post-init user code here
        }//GEN-BEGIN:|60-getter|2|
        return exitCommand1;
    }
    //</editor-fold>//GEN-END:|60-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: image2 ">//GEN-BEGIN:|62-getter|0|62-preInit
    /**
     * Returns an initiliazed instance of image2 component.
     * @return the initialized component instance
     */
    public Image getImage2() {
        if (image2 == null) {//GEN-END:|62-getter|0|62-preInit
                // write pre-init user code here
            try {//GEN-BEGIN:|62-getter|1|62-@java.io.IOException
                image2 = Image.createImage("/lastfm-logo1.jpg");
            } catch (java.io.IOException e) {//GEN-END:|62-getter|1|62-@java.io.IOException
                    e.printStackTrace();
            }//GEN-LINE:|62-getter|2|62-postInit
                // write post-init user code here
        }//GEN-BEGIN:|62-getter|3|
        return image2;
    }
    //</editor-fold>//GEN-END:|62-getter|3|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: form1 ">//GEN-BEGIN:|66-getter|0|66-preInit
    /**
     * Returns an initiliazed instance of form1 component.
     * @return the initialized component instance
     */
    public Form getForm1() {
        if (form1 == null) {//GEN-END:|66-getter|0|66-preInit
                // write pre-init user code here
            form1 = new Form("FormSplash", new Item[] { imageItem, getStringItem() });//GEN-LINE:|66-getter|1|66-postInit
                // write post-init user code here
        }//GEN-BEGIN:|66-getter|2|
        return form1;
    }
    //</editor-fold>//GEN-END:|66-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem ">//GEN-BEGIN:|68-getter|0|68-preInit
    /**
     * Returns an initiliazed instance of stringItem component.
     * @return the initialized component instance
     */
    public StringItem getStringItem() {
        if (stringItem == null) {//GEN-END:|68-getter|0|68-preInit
                // write pre-init user code here
            stringItem = new StringItem("Por favor aguarde...", "Conectando ao servidor!");//GEN-LINE:|68-getter|1|68-postInit
                // write post-init user code here
        }//GEN-BEGIN:|68-getter|2|
        return stringItem;
    }
    //</editor-fold>//GEN-END:|68-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: form2 ">//GEN-BEGIN:|69-getter|0|69-preInit
    /**
     * Returns an initiliazed instance of form2 component.
     * @return the initialized component instance
     */
    public Form getForm2() {
        if (form2 == null) {//GEN-END:|69-getter|0|69-preInit
                // write pre-init user code here
            form2 = new Form("form2", new Item[] { getImageItem1(), getStringItem1() });//GEN-LINE:|69-getter|1|69-postInit
                // write post-init user code here
        }//GEN-BEGIN:|69-getter|2|
        return form2;
    }
    //</editor-fold>//GEN-END:|69-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: imageItem1 ">//GEN-BEGIN:|70-getter|0|70-preInit
    /**
     * Returns an initiliazed instance of imageItem1 component.
     * @return the initialized component instance
     */
    public ImageItem getImageItem1() {
        if (imageItem1 == null) {//GEN-END:|70-getter|0|70-preInit
                // write pre-init user code here
            imageItem1 = new ImageItem("", getImage(), ImageItem.LAYOUT_CENTER | Item.LAYOUT_TOP | Item.LAYOUT_BOTTOM | Item.LAYOUT_VCENTER | Item.LAYOUT_2, "<Imagem perdida>");//GEN-LINE:|70-getter|1|70-postInit
                // write post-init user code here
        }//GEN-BEGIN:|70-getter|2|
        return imageItem1;
    }
    //</editor-fold>//GEN-END:|70-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem1 ">//GEN-BEGIN:|71-getter|0|71-preInit
    /**
     * Returns an initiliazed instance of stringItem1 component.
     * @return the initialized component instance
     */
    public StringItem getStringItem1() {
        if (stringItem1 == null) {//GEN-END:|71-getter|0|71-preInit
                // write pre-init user code here
            stringItem1 = new StringItem("Por Favor aguarde....", "Identificando local!");//GEN-LINE:|71-getter|1|71-postInit
                // write post-init user code here
        }//GEN-BEGIN:|71-getter|2|
        return stringItem1;
    }
    //</editor-fold>//GEN-END:|71-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: image ">//GEN-BEGIN:|72-getter|0|72-preInit
    /**
     * Returns an initiliazed instance of image component.
     * @return the initialized component instance
     */
    public Image getImage() {
        if (image == null) {//GEN-END:|72-getter|0|72-preInit
                // write pre-init user code here
            try {//GEN-BEGIN:|72-getter|1|72-@java.io.IOException
                image = Image.createImage("/bt.jpg");
            } catch (java.io.IOException e) {//GEN-END:|72-getter|1|72-@java.io.IOException
                    e.printStackTrace();
            }//GEN-LINE:|72-getter|2|72-postInit
                // write post-init user code here
        }//GEN-BEGIN:|72-getter|3|
        return image;
    }
    //</editor-fold>//GEN-END:|72-getter|3|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: okCommand3 ">//GEN-BEGIN:|76-getter|0|76-preInit
    /**
     * Returns an initiliazed instance of okCommand3 component.
     * @return the initialized component instance
     */
    public Command getOkCommand3() {
        if (okCommand3 == null) {//GEN-END:|76-getter|0|76-preInit
            // write pre-init user code here
            okCommand3 = new Command("Ok", Command.OK, 0);//GEN-LINE:|76-getter|1|76-postInit
            // write post-init user code here
        }//GEN-BEGIN:|76-getter|2|
        return okCommand3;
    }
    //</editor-fold>//GEN-END:|76-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: textBox1 ">//GEN-BEGIN:|74-getter|0|74-preInit
    /**
     * Returns an initiliazed instance of textBox1 component.
     * @return the initialized component instance
     */
    public TextBox getTextBox1() {
        if (textBox1 == null) {//GEN-END:|74-getter|0|74-preInit
            // write pre-init user code here
            textBox1 = new TextBox("PlaceMusic", "Obrigado por utilizar o PlaceMusic,\n o aplicativo foi encerrado com sucesso!", 100, TextField.ANY);//GEN-BEGIN:|74-getter|1|74-postInit
            textBox1.addCommand(getOkCommand3());
            textBox1.setCommandListener(this);//GEN-END:|74-getter|1|74-postInit
            // write post-init user code here
        }//GEN-BEGIN:|74-getter|2|
        return textBox1;
    }
    //</editor-fold>//GEN-END:|74-getter|2|

    /**
     * Returns a display instance.
     *
     * @return the display instance.
     */
    public Display getDisplay() {
        return Display.getDisplay(this);
    }

    /**
     * Exits MIDlet.
     */
    public void exitMIDlet() {
 
        switchDisplayable(null, null);
        destroyApp(true);
        notifyDestroyed();
    }

    /**
     * Called when MIDlet is started. Checks whether the MIDlet have been
     * already started and initialize/starts or resumes the MIDlet.
     */
    public void startApp() {
        if (midletPaused) {
            resumeMIDlet();
        } else {
            initialize();
            startMIDlet();
        }
        midletPaused = false;
    }

    /**
     * Called when MIDlet is paused.
     */
    public void pauseApp() {
        midletPaused = true;
    }

    /**
     * Called to signal the MIDlet to terminate.
     *
     * @param unconditional
     *            if true, then the MIDlet has to be unconditionally terminated
     *            and all resources has to be released.
     */
    public void destroyApp(boolean unconditional)
    {

    }
}
